﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

namespace X.WPF.Controls.CustomControls
{
    /// <summary>
    /// 表单项
    /// </summary>
    [ContentProperty("Content")]
    public class FormItem : Control
    {

        #region # 字段及构造器

        /// <summary>
        /// 静态构造器
        /// </summary>
        static FormItem()
        {
            //注册依赖属性
            FormItem.RequiredProperty = DependencyProperty.Register(nameof(FormItem.Required), typeof(bool), typeof(FormItem), new PropertyMetadata(false));
            FormItem.LabelProperty = DependencyProperty.Register(nameof(FormItem.Label), typeof(string), typeof(FormItem), new PropertyMetadata(string.Empty));
            FormItem.LabelTemplateProperty = DependencyProperty.Register(nameof(FormItem.LabelTemplate), typeof(DataTemplate), typeof(FormItem), new PropertyMetadata());
            FormItem.ValidateProperty = DependencyProperty.Register(nameof(FormItem.Validate), typeof(bool), typeof(FormItem), new PropertyMetadata(true));
            FormItem.ValidateMessageProperty = DependencyProperty.Register(nameof(FormItem.ValidateMessage), typeof(string), typeof(FormItem), new PropertyMetadata(string.Empty));
            FormItem.DescriptionProperty = DependencyProperty.Register(nameof(FormItem.Description), typeof(string), typeof(FormItem), new PropertyMetadata(string.Empty));
            FormItem.ContentProperty = DependencyProperty.Register(nameof(FormItem.Content), typeof(object), typeof(FormItem), new PropertyMetadata());

        }

        /// <summary>
        /// 默认构造器
        /// </summary>
        public FormItem()
        {
        }

        #endregion

        #region # 依赖属性 

        #region 是否必填 —— bool Required
        /// <summary>
        /// 是否必填依赖属性
        /// </summary>
        public static DependencyProperty RequiredProperty;

        /// <summary>
        /// 是否必填
        /// </summary>
        public bool Required
        {
            get => (bool)base.GetValue(FormItem.RequiredProperty);
            set => base.SetValue(FormItem.RequiredProperty, value);
        }
        #endregion

        #region 标签 —— string Label
        /// <summary>
        /// 标签依赖属性
        /// </summary>
        public static DependencyProperty LabelProperty;

        /// <summary>
        /// 标签
        /// </summary>
        public string Label
        {
            get => (string)base.GetValue(FormItem.LabelProperty);
            set => base.SetValue(FormItem.LabelProperty, value);
        }
        #endregion

        #region 标签模版 —— DataTemplate LabelTemplate
        /// <summary>
        /// 标签模版依赖属性
        /// </summary>
        public static DependencyProperty LabelTemplateProperty;

        /// <summary>
        /// 标签模版
        /// </summary>
        public DataTemplate LabelTemplate
        {
            get => (DataTemplate)base.GetValue(FormItem.LabelTemplateProperty);
            set => base.SetValue(FormItem.LabelTemplateProperty, value);
        }
        #endregion

        #region 校验  —— string Validate
        /// <summary>
        /// 校验依赖属性
        /// </summary>
        public static DependencyProperty ValidateProperty;

        /// <summary>
        /// 校验信息
        /// </summary>
        public bool Validate
        {
            get => (bool)base.GetValue(FormItem.ValidateProperty);
            set => base.SetValue(FormItem.ValidateProperty, value);
        }
        #endregion

        #region 校验信息  —— string ValidateMessage
        /// <summary>
        /// 校验信息依赖属性
        /// </summary>
        public static DependencyProperty ValidateMessageProperty;

        /// <summary>
        /// 校验信息
        /// </summary>
        public string ValidateMessage
        {
            get => (string)base.GetValue(FormItem.ValidateMessageProperty);
            set => base.SetValue(FormItem.ValidateMessageProperty, value);
        }
        #endregion

        #region 标签模版 —— object Content
        /// <summary>
        /// 标签模版依赖属性
        /// </summary>
        public static DependencyProperty ContentProperty;

        /// <summary>
        /// 标签模版
        /// </summary>
        public object Content
        {
            get => (object)base.GetValue(FormItem.ContentProperty);
            set => base.SetValue(FormItem.ContentProperty, value);
        }
        #endregion

        #region 描述 —— string Description
        /// <summary>
        /// 描述依赖属性
        /// </summary>
        public static DependencyProperty DescriptionProperty;

        /// <summary>
        /// 描述
        /// </summary>
        public string Description
        {
            get => (string)base.GetValue(FormItem.DescriptionProperty);
            set => base.SetValue(FormItem.DescriptionProperty, value);
        }
        #endregion

        #endregion

        #region # 路由事件

        #endregion

        #region # 事件处理程序

        #endregion

        #region # 回调方法

        #endregion

        #region # 方法

        #endregion
    }
}
